<?php
/**
 * Character model test file.
 *
 * Infectamic: browser game (http://infectamic.goldzoneweb.info)
 * Copyright 2011, Loic Chardonnet
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 */

App::uses('Character', 'Model');

/**
 * Class for Character model test.
 */
class CharacterTestCase extends CakeTestCase {
    public $fixtures = array('app.character');

    public function setup() {
        parent::setUp();
        $this->Character = ClassRegistry::init('Character');
    }

    public function testRandomGeneration() {
        $nbCharactersBefore = $this->Character->find('count');

        $this->Character->generateRandomly();

        $nbCharactersAfter = $this->Character->find('count');

        $this->assertEqual($nbCharactersAfter, $nbCharactersBefore + 1);
    }

    public function testCountGeneratedForLastDay() {
        $nbCharactersBefore = $this->Character->countGeneratedForLastDay();

        $expectedNbGeneratedForLastDay = LIMIT_OF_GENERATED_CHARACTERS;
        for ($generatedCharacters = 0; $generatedCharacters < $expectedNbGeneratedForLastDay; $generatedCharacters++) {
            $this->Character->generateRandomly();
        }

        $nbGeneratedForLastDay = $this->Character->countGeneratedForLastDay();

        $this->assertEqual($nbGeneratedForLastDay, $expectedNbGeneratedForLastDay + $nbCharactersBefore);
    }

    public function testRemoveDeads() {
        $this->Character->removeDeads();

        $nbCharacters = $this->Character->find('count');

        $expectedNbCharacters = 1;

        $this->assertEqual($nbCharacters, $expectedNbCharacters);
    }
}
